let enemyPlaneIndex = 0
const getEnemyPlaneId = ()=>{
    return enemyPlaneIndex++
}

class EnemyPlane{
    constructor(option){
        this.id = getEnemyPlaneId()
        this.dom = createImg()
        this.dom.src = option.resource
        this.width = 308
        this.height = 207
        this.top = -200
        this.left = Math.random()*(750-308)
        this.speed = option.speed
    }
    patch(){
        render(this.dom,this.top,this.left)
    }
    move(){
        this.top += this.speed
    }
    //出下边界
    isOk(){
        if(this.top > 1100){
            return false
        }
        return true
    }
}

//定时生成敌机数组
const enemyPlanesArr = []


const updateEnemyPlanesArr = ()=>{
    const option = {
        speed: 0.5,
        resource: './assets/enemy.png'
    }
    const enemyPlane = new EnemyPlane(option)
    enemyPlanesArr.push(enemyPlane)
    enemyPlane.patch()
    app.appendChild(enemyPlane.dom)
}

setInterval(updateEnemyPlanesArr,1000)


//定时生成子弹数组
const enemyBulletsArr = []
const updateEnemyBulletsArr = ()=>{
    enemyPlanesArr.forEach((item)=>{
        const option = {
            top: item.top + 207-60,
            left: item.left + 154 -30,
            speed: 8,
            resource: './assets/bunny.png',
            dir: 1
        }
        const enemyBullet = new EnemyBullet(option)
        enemyBulletsArr.push(enemyBullet)
        enemyBullet.patch()
        app.appendChild(enemyBullet.dom)
    })
}

setInterval(updateEnemyBulletsArr,1500)